import { ApiResponse, LoginType, Token } from '@/types/data'
import { RootThunkAction } from '@/types/store'
import request from '@/utils/request'
import { setToken } from '@/utils/storage'
export const login = (values: LoginType): RootThunkAction => {
  return async (dispatch) => {
    const res = await request.post<ApiResponse<Token>>(
      '/authorizations',
      values
    )
    // console.log(res.data.data.refresh_token)
    dispatch({
      type: 'login/login',
      payload: res.data.data
    })

    // 存储到本地
    setToken(res.data.data)
  }
}

export const getCode = (mobile: string): RootThunkAction => {
  return async (dispatch) => {
    await request.get(`/sms/codes/${mobile}`)
  }
}
